/**
 * Copyright 2005 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.edi.runtime.control
{
	
	import com.edi.runtime.component.EDIApplication;
	
	import mx.controls.Label;
	import mx.controls.dataGridClasses.DataGridListData;
	import mx.controls.listClasses.BaseListData;

	/**
	 * 时间组件渲染器,可格式化显示的时间类型.
	 * 
	 */    
	public class DateItemRender extends Label
	{
		private var _listData:DataGridListData;
		private var _data:Object;

		public var displayTypes:String = "datetime";
		/**
		 * 
		 * 构造函数
		 */		
		public function DateItemRender() 
		{
            super();

		}
        /**
         * 复写 get data 获取数据函数
         * @return 
         * 
         */		
        override public function get data():Object
		{
		    return _data;
		}
		
		/**
		 * 复写获取数据函数，判断数据是否有效
		 * @param value
		 * 
		 */
		override public function set data(value:Object):void
		{
			
		    _data = value;
		    
		    if (_data is XML)
		    {
		    	if(_listData.dataField){
		    		var labelText:String = "";
		    		if(displayTypes.toLowerCase() == "datetime"){
		    			labelText = String(_data[_listData.dataField]).substring(0,19);
		    		}else if(displayTypes.toLowerCase() == "date"){
		    			labelText = String(_data[_listData.dataField]).substring(0,10);
		    		}
		    		text = labelText;
		    		super.data = labelText;
		    			
		    	}
		    	
		    }
		    
		}
        /**
         * 在EDIDataGrid列表中的数据,包括行列位置信息等
         * @return 
         * 
         */        
        override public function get listData():BaseListData
		{
		    return _listData;
		}
		/**
		 * 在EDIDataGrid列表中的数据,包括行列位置信息等
		 * @param value
		 * 
		 */
		override public function set listData(value:BaseListData):void
		{
		    _listData = DataGridListData(value);
		} 
		
	}
}